﻿namespace Microsoft.Web.Helpers.Tests
{
    using System;
    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Data.Services.Providers;

    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class MockDataService : DataService<MockServiceEntities>, IServiceProvider
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.UseVerboseErrors = true;
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }

        public object GetService(Type serviceType)
        {
            if (serviceType == typeof(IDataServiceStreamProvider))
            {
                // Create an instance of the stream provider to return to the data service.
                MockStreamProvider provider = new MockStreamProvider();

                return provider;
            }

            return null;
        }
    }
}
